#pragma once

#include <vector>

struct WSAOVERLAPPEDEX;

class COverlappedCompletionRoutineModel
	: public INetworkLib
{
	ON_CONNECT_FUNCTOR		m_onConnectFunctor;
	ON_ACCEPT_FUNCTOR		m_onAcceptFunctor;	
	ON_DISCONNECT_FUNCTOR	m_onDisconnectFunctor;
	ON_RECV_FUNCTOR			m_onRecvFunctor;

	IAsyncSendQueue*		m_pAsyncSendQueue;

	static void CALLBACK	sendCompletionRoutine(DWORD Error, DWORD BytesTransferred, LPWSAOVERLAPPED pOverlapped, DWORD InFlags);
	static void CALLBACK	recvCompletionRoutine(DWORD Error, DWORD BytesTransferred, LPWSAOVERLAPPED pOverlapped, DWORD InFlags);
	static UINT __stdcall	acceptWorkerThread( void* pArguments );

	bool					postRecv( SOCKET clientSocket, WSAOVERLAPPEDEX* pOverlapped );
	bool					Send(SOCKET socket, size_t bytesSent);
public:
	COverlappedCompletionRoutineModel(void);
	virtual ~COverlappedCompletionRoutineModel(void);

	virtual bool	Initialize(ON_CONNECT_FUNCTOR onConnect
							, ON_ACCEPT_FUNCTOR onAccept
							, ON_DISCONNECT_FUNCTOR onDisconnect
							, ON_RECV_FUNCTOR onRecv		
							) override;

	virtual bool	Connect(const std::tstring& ip, WORD port) override;

	virtual bool	Send(SOCKET socket, IStreamBuffer& stream) override;

	virtual bool	Disconnect(SOCKET socket) override;

	virtual bool	Listen(const std::tstring& ip, WORD port, int backlog) override;

	virtual void	Release() override;
	


};

